/****************************************************************************/
/***                                                                      ***/
/***   (C) 2012-2014 Dierk Ohlerich et al., all rights reserved.          ***/
/***                                                                      ***/
/***   Released under BSD 2 clause license, see LICENSE.TXT               ***/
/***                                                                      ***/
/****************************************************************************/

mtrl CubeShader 
{
  struct ia2vs
  {
    float3 pos : POSITION;
    float2 uv0 : TEXCOORD0;
  };

  struct vs2ps
  {
    float2 uv0 : TEXCOORD0;
  };

  cbuffer cbvs : vs(0) : register(0)
  {
    row_major float4x4 ms2ss;
    float3 tx;
    float3 ty;
  };

  // hlsl3
  
  vs hlsl3
  {
    void main(in ia2vs i,out vs2ps o,out float4 tpos : POSITION)
    {
      float2 d;
      d.x = i.uv0.x*2.0-1.0;
      d.y = i.uv0.y*2.0-1.0;
      float3 _pos = i.pos;
      _pos += tx*d.xxx;
      _pos -= ty*d.yyy;
      tpos = mul(ms2ss,float4(_pos,1.0));
      o.uv0 = i.uv0;
    }
  };

  ps hlsl3
  {
    SamplerState sam0 : register(s0);
    void main(in vs2ps i,out float4 r : COLOR)
    {
      r = tex2D(sam0,i.uv0);
    }
  };

  // hlsl5
  
  vs hlsl5
  {
    void main(in ia2vs i,out vs2ps o,out float4 tpos : SV_Position)
    {
      float2 d;
      d.x = i.uv0.x*2.0-1.0;
      d.y = i.uv0.y*2.0-1.0;
      float3 _pos = i.pos;
      _pos += tx*d.xxx;
      _pos += ty*d.yyy;
      tpos = mul(ms2ss,float4(_pos,1.0));
      o.uv0 = i.uv0;
    }
  };

  ps hlsl5
  {
    SamplerState sam0 : register(s0);
    Texture2D tex0 : register(t0);
    void main(in vs2ps i,out float4 r : SV_Target)
    {
      r = tex0.Sample(sam0,i.uv0);
    }
  };

  // glsl1
  
  vs glsl1
  {
    void main()
    {
      vec2 d;
      d.x = i_uv0.x*2.0-1.0;
      d.y = i_uv0.y*2.0-1.0;
      vec3 _pos = i_pos;
      _pos += tx*d.xxx;
      _pos += ty*d.yyy;
      gl_Position = ms2ss*vec4(_pos,1.0);
      o_uv0 = i_uv0;
    }
  };

  ps glsl1
  {
    uniform sampler2D sam0;
    void main()
    {
      gl_FragColor = texture2D(sam0,i_uv0);
    }
  };
} 

/****************************************************************************/
